﻿using An_Im.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace An_Im.UI
{
    /// <summary>
    /// AnImSliderControl.xaml 的交互逻辑
    /// </summary>
    public partial class AnImSliderControl : UserControl
    {
        private ObservableCollection<MarcoSliderInfomation> _marcoSliderInfomations;
        public AnImSliderControl()
        {
            InitializeComponent();
            _marcoSliderInfomations = new ObservableCollection<MarcoSliderInfomation>();
            sliderList.ItemsSource = _marcoSliderInfomations;
        }

        private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            var slider = sender as Slider;
            var datacontext = slider.DataContext as MarcoSliderInfomation;
            if (datacontext == null) return;
            try
            {
                CoreManipulator.App.Run(datacontext.Name, new object[] { datacontext.Value/100 });

            }
            catch
            {

            }
     

        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var elem = sender as FrameworkElement;
            var datacontext = elem.DataContext as MarcoSliderInfomation;
            if (datacontext == null) return;
            _marcoSliderInfomations.Remove(datacontext);
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            _marcoSliderInfomations.Add(new MarcoSliderInfomation());
        }
    }
}
